public class RoundRobinQueue {
    public int[] array;
    public int front;
    public int end;
    public RoundRobinQueue(int n){
        array=new int[n+1];
    }
    //入队
    public boolean enQueue(int value){
       if (isFull()){
           return false;
       }
       array[end]=value;
       end=(end+1)%array.length;
       return true;
    }
    //出队
    public boolean deQueue() {
        if(isEmpty()) {
            return false;
        }
        front = (front+1)%array.length;;
        return true;
    }
    //获取队头元素
    public int front(){
        if (isEmpty()){
            return -1;
        }
        return array[front];
    }
    //获取队尾元素
    public int rear() {
        if(isEmpty()) {
            return -1;
        }
        int index = (end == 0) ? array.length-1 : end-1;
        return array[index];
    }
    public boolean isEmpty(){
        return front==end;
    }
    public boolean isFull() {
        if( (end+1) % array.length == front) {
            return true;
        }
        return false;
    }
    public void print(){
        if (isEmpty()) {
            System.out.println("队列空");
            return;
        }
        int i = front;
        while (i != end) {
            System.out.print(array[i] + " ");
            i = (i + 1) % array.length;
        }
        System.out.println();
    }
}
